<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Transaksi_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	//==================================================================
	function get_peminjaman($nisn){
		
		$this->db->select('*');
		$this->db->from('tb_perpus_pinjam a'); 
		$this->db->join('tb_perpus_eksemplar b','a.KODE_EKSEMPLAR=b.KODE_EKSEMPLAR');
		$this->db->join('tb_perpus_buku c','c.ID_BUKU=b.ID_BUKU');
		$this->db->where('a.NISN',$nisn);
		$this->db->where('a.STATUS',1);//TERPINJAM
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('tb_perpus_pinjam a'); 
		$this->db->join('tb_perpus_eksemplar b','a.KODE_EKSEMPLAR=b.KODE_EKSEMPLAR');
		$this->db->join('tb_perpus_buku c','c.ID_BUKU=b.ID_BUKU');
		$this->db->where('a.NISN',$nisn);
		$this->db->where('a.STATUS',1);
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function getDenda($jenis){
		
		//Select table column
		$this->db->select('*');
		$this->db->from('tb_perpus_konfigurasi');
		$this->db->where('JENIS_ANGGOTA',$jenis);
		$query = $this->db->get();
		return $query;
	}
	
	function insert_peminjaman($data){
		$this->db->insert('tb_perpus_pinjam',$data);
	}
	
	function update_peminjaman($data, $id){
		$this->db->where('ID_PINJAM',$id);
		$this->db->update('tb_perpus_pinjam',$data);
	}
	
	function get_jmlpinjam($nisn){
		$this->db->select('count(*) as jmlpinjam');
		$this->db->from('tb_perpus_pinjam');
		$this->db->where('NISN',$nisn);
		$this->db->where('STATUS',1);
		$query = $this->db->get();
		return $query;
	}
	function get_tenggat($id){
		$this->db->select('*');
		$this->db->from('tb_perpus_pinjam');
		$this->db->where('ID_PINJAM',$id);
		$query = $this->db->get();
		return $query;
	}
	function insert_denda($data){
		$this->db->insert('tb_perpus_denda',$data);
	}
}

?>
